<?php
//header('Content-type: application/json');
class Admin_Factor_Controller extends Base_Controller {

    public function action_index()
    {        
        return View::make('admin/factor');
    }


    //后台表格获取数据地址
    public function action_getdata()
    {
        $factorPgData = DB::table('factor')
                ->where('dele','=',1)
                ->paginate(10);
        $res = array(
            'code'=>0,
            'msg'=>'',
            'count'=>$factorPgData->total,
            'data'=>$factorPgData->results,
            );
        return Response::json($res); //把数据转化成json返回
    }

    //后台表格数据删除ajax请求地址
    public function action_dele()
    {
        $id = Input::get('id');
        $dele = -1;
        $str = DB::table('factor')->where('id','=',$id)->update(array('dele'=>$dele));
        if($str){
            $data = array(
                'code'=>'200',
                'msg'=>'删除成功'
                );
        }else{
            $data = array(
                'code'=>'400',
                'msg'=>'删除失败'
                );
        }
        return json_encode($data);


    }


    public function action_dochange()
    {

        $id = Input::get('id');
        $lien = Input::get('lien');
        $lien_number = Input::get('lien_number');
        $explanination = Input::get('explanination');
     
        $str = DB::table('factor')->where('id','=',$id)->update(array('lien'=>$lien,'lien_number'=>$lien_number,'explanination'=>$explanination));
        if($str){
            return View::make('jump/success',array('msg'=>'修改成功,','time'=>1));
        }else{
            
            return View::make('jump/success',array('msg'=>'修改失败','time'=>2));
        }

    }


    //后台表格数据编辑url
    public function action_change()
    {
        $id = Input::get('id');
        $str = DB::table('factor')->where('id','=',$id)->first();
        return View::make('admin/factorchange',array('str'=>$str));
        //return View::make('admin/orderchange',array('str'=>$str);
    }


    //查看详情url
    public function action_detail()
    {

        $id = Input::get('id');
        $str = DB::table('factor')->where('id','=',$id)->first();
        return View::make('admin/factordetail',array('str'=>$str));

    }


    //后台添加顺位值url
    public function action_addfactor()
    {
        return View::make('admin/addfactor');
    }



    public function action_doaddfactor()
    {

        $lien = hnput::get('lien');
        $lien_number = Input::get('lien_number');
        $explanination = Input::get('explanination');
        //$explanination = ltrim($explanination);
        $str = DB::table('factor')->insert(array('lien'=>$lien,'lien_number'=>$lien_number,'explanination'=>$explanination));
        if($str){
            $data = array(
                'code'=>'200',
                'msg'=>'添加成功'
                );
        }else{
            $data = array(
                'code'=>'400',
                'msg'=>'添加失败'
                );
        }
        return json_encode($data);

    }

































}